package com.xikang.ice.common.interceptor;

import Ice.*;
import Ice.Object;
import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * dispatch interceptor 用于日志监控
 * <p>
 *
 * @author gaochuan
 * @version 0.1.0
 * @date
 * @since
 */
public class PreDispatchInterceptor extends DispatchInterceptor {
    private static final Map<Identity, Object> iceDispatchMap = new ConcurrentHashMap<Identity, Object>();
    private static final PreDispatchInterceptor instance = new PreDispatchInterceptor();

    public static DispatchInterceptor getInstance() {
        return instance;
    }

    public static DispatchInterceptor add(Object servant, Identity id) {
        iceDispatchMap.put(id, servant);
        return instance;
    }

    @Override
    public DispatchStatus dispatch(Request request) {
        {
            Identity identity = request.getCurrent().id;
            return iceDispatchMap.get(identity).ice_dispatch(request);
        }
    }
}
